package org.traffometer.packet;

import java.util.Date;

import junit.framework.TestCase;

import org.traffometer.packet.location.Hemisphere;
import org.traffometer.packet.location.Latitude;
import org.traffometer.packet.location.Location;
import org.traffometer.packet.location.LocationException;
import org.traffometer.packet.location.Longitude;

/**
 * Tests the TraffoPacket functionality. 
 *
 * @author Aaron A. Kagawa
 * @version $Id$
 */
public class TestTraffoPacket extends TestCase {

  /** 
   * Tests the construction of a TraffoPacket object.
   * @throws LocationException If an unexpected problem occurs. 
   */
  public void testConstructor() throws LocationException {
    Longitude longitudeOne = new Longitude(1, 1, 1, Hemisphere.East);
    Latitude latitudeOne = new Latitude(1, 1, 1, Hemisphere.North);
    Location locationOne = new Location(longitudeOne, latitudeOne);
    Date timestampOne = new Date();
    
    Longitude longitudeTwo = new Longitude(2, 2, 2, Hemisphere.West);
    Latitude latitudeTwo = new Latitude(2, 2, 2, Hemisphere.South);
    Location locationTwo = new Location(longitudeTwo, latitudeTwo);
    Date timestampTwo = new Date();
    
    TraffoPacket traffoPacket = new TraffoPacket(VehicleType.BUS, locationOne, timestampOne, 
        locationTwo, timestampTwo);
    assertEquals("Checking the vehicle type retrieval", VehicleType.BUS, 
        traffoPacket.getVehicleType());
    assertEquals("Checking the location of the first pair", locationOne, 
        traffoPacket.getLocationTimestampPairOne().getLocation());
    assertEquals("Checking the timestamp of the second pair", timestampTwo, 
        traffoPacket.getLocationTimestampPairTwo().getTimestamp());
  }

  /** 
   * Tests the construction of a TraffoPacket object.
   * @throws LocationException If an unexpected problem occurs. 
   */
  public void testDistance() throws LocationException {
    Longitude longitudeOne = new Longitude(157, 55, 13.50, Hemisphere.West);
    Latitude latitudeOne = new Latitude(21, 20, 15.75, Hemisphere.North);
    Location locationOne = new Location(longitudeOne, latitudeOne);
    Date timestampOne = new Date();
    //System.out.println(locationOne.toString());
    
    Longitude longitudeTwo = new Longitude(157, 55, 36.50, Hemisphere.West);
    Latitude latitudeTwo = new Latitude(21, 20, 19.75, Hemisphere.North);
    Location locationTwo = new Location(longitudeTwo, latitudeTwo);
    Date timestampTwo = new Date();
    //System.out.println(locationTwo.toString());
    
    TraffoPacket traffoPacket = new TraffoPacket(VehicleType.BUS, locationOne, timestampOne, 
        locationTwo, timestampTwo);
    // about 0.41 Miles
    assertEquals("checking the distance between the two locations", 
        0.41, traffoPacket.distanceBetween(), 0.01);
  }
}